/**
 * Author: 老洋
 * Date:  2021/3/28 21:13
 */
package com.yyy.config;


import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String l = request.getParameter("l");  //从request中获取：自己设置的解析语言
        Locale locale = request.getLocale();     //获取：默认的本地语言解析

        if( l != null && l.length() != 0){       //如果自己的解析语言不为空，且长度不为0
            String[] language = l.split("_");   //将其分割

            //language[0]国家；  language[1]地区
            locale = new Locale(language[0], language[1]);    //将分割后的：语言封装到locale类
        }

        return locale;                          //返回：需要显示（解析语言）
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}